package game;
import java.io.Serializable;
import java.util.HashMap;

/**
 * Field is the arena for snakes.  
 * @author Sarun Wongtanakarn 5510546166
 * @author Apiwat Jierakulpanit 5510546212
 * @Version 2013.04.25
 */
public class Field implements Serializable {

	private int width;
	private int height;
	private HashMap<Point, Integer> field;
	public final Point[][] POINT;
	
	/**
	 * Creates a new Field.
	 * 
	 * @param width width of the field.
	 * @param height height of the field;
	 */
	public Field(int width, int height) {
		this.width = width;
		this.height = height;
		POINT = new Point[width][height];
		field = new HashMap<Point, Integer>();

		for (int y = height - 1; y >= 0; y--) {
			for (int x = 0; x < width; x++) {
				POINT[x][y] = new Point(x, y);
				field.put(POINT[x][y], 0);
			}
		}
			
	}
	
	/**
	 * Gets value of the specific point.
	 * @param point point to be determined.
	 * @return value of the determined point.
	 */
	public int getValue(Point point) {
		return field.get(point);
	}
	
	/**
	 * Sets value of the specific point.
	 * @param point point to be set.
	 * @param newValue a new value to for setting the point. 
	 */
	public void setValue(Point point, Integer newValue) {
		field.put(point, newValue);
	}

	/**
	 * Gets the width of field.
	 * @return width of field.
	 */
	public int getWidth() {
		return width;
	}

	/**
	 * Gets the height of field.
	 * @return height of field.
	 */
	public int getHeight() {
		return height;
	}
}
